<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        h3 {
            margin: 50px 0;
        }
        .center01 {
            width: 100px;
            height: 100px;
            /* margin: auto; */
            /* margin: 0 auto; */
            margin-left: auto;
            margin-right: auto;
            background-color: pink;
        }
        .center02 {
            width: 200px;
            height: 200px;
            position: absolute;
            left: 50%;
            margin-left: -100px;
            background-color: skyblue;
        }
        .center03 {
            width: 400px;
            height: 100px;
            border: 1px solid #000;
            margin: 50px auto;    
            background-color: yellow;
        }
        .center04 {
            width: 400px;
            height: 100px;
            border: 1px solid #000;
            margin: 100px auto;
        }
        .center04 p {
            position: relative;
            left: 50%;
            width: 800px;
            height: 100px;
            margin-left: -400px;
            background-color: gold;
        }
        .center05 {
            position: relative;
            width: 500px;
            height: 100px;
            border: 1px solid #000;
            margin: 0 auto;
        }
        .center05 p {
            position: absolute;
            left: 50%;
            width: 100px;
            height: 100px;
            padding: 0 20px;
            transform: translate(-50%);
            background: yellowgreen;
        }
    </style>
</head>
<body>
    <h3>1. 实现一个盒子水平居中（起码两种方式）。</h3>
    <div class="center01">1</div>
    <div class="center02">2</div>
    <div class="center03">3</div>
    <div class="center04">
        <p>4</p>
    </div>
    <div class="center05">
        <p>5</p>
    </div>
</body>
</html>